home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / aplictns / plplot26 / part09 < prev    next >
Encoding:
Internet Message Format  |  1990-01-14  |  28.6 KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i010: plplot 2.6 - C library for making scientific plots, Part09/12
  5. Message-ID: <10982@xanth.cs.odu.edu>
  6. Date: 14 Jan 90 23:33:18 GMT
  7. Sender: tadguy@cs.odu.edu
  8. Reply-To: Anthony M. Richardson <amr@dukee.egr.duke.edu>
  9. Lines: 998
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11.  
  12. Submitted-by: Anthony M. Richardson <amr@dukee.egr.duke.edu>
  13. Posting-number: Volume 90, Issue 010
  14. Archive-name: applications/plplot-2.6/part09
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 9 (of 12)."
  23. # Contents:  Amiga/plsupport.c
  24. # Wrapped by tadguy@xanth on Sun Jan 14 18:11:56 1990
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'Amiga/plsupport.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'Amiga/plsupport.c'\"
  28. else
  29. echo shar: Extracting \"'Amiga/plsupport.c'\" \(26014 characters\)
  30. sed "s/^X//" >'Amiga/plsupport.c' <<'END_OF_FILE'
  31. X#include "plplot.h"
  32. X#include "plamiga.h"
  33. X#include <stdio.h>
  34. X#ifdef LATTICE_50
  35. X  #include <stdlib.h>
  36. X  #include <string.h>
  37. X#else
  38. X  extern char *calloc();
  39. X  extern void free();
  40. X  /* Psuedo-ANSI compatibility for AZTEC */
  41. X  #define memset(ptr,val,len)        setmem(ptr,len,val)
  42. X#endif
  43. X#include <libraries/dosextens.h>
  44. X
  45. Xextern FILE *PlotFile;
  46. Xextern short fbuffer;
  47. X
  48. X/* I borrowed most of the IFF and preferences stuff from Tom Rokicki */
  49. Xstatic union printerIO {
  50. X   struct IOStdReq ios;
  51. X   struct IODRPReq iodrp;
  52. X   struct IOPrtCmdReq iopc;
  53. X} *printerIO;
  54. X
  55. Xstatic struct PrinterData *PD;
  56. Xstatic struct PrinterExtendedData *PED;
  57. Xstatic struct MsgPort *replyport;
  58. Xstatic struct RastPort rastport;
  59. Xstatic struct BitMap Bitmap;
  60. Xstatic short dummycolors[] = { 0x0000, 0x0fff };
  61. Xstatic struct ColorMap dummyColorMap = { NULL, NULL, 2, (APTR)&dummycolors };
  62. X
  63. X
  64. Xstatic void doio()
  65. X{
  66. X   register struct IODRPReq *ioreq;
  67. X
  68. X   ioreq = &printerIO->iodrp;
  69. X   SendIO((struct IORequest *)ioreq);
  70. X   while(1) {
  71. X      if(GetMsg(replyport) == NULL)
  72. X         Wait(1L << replyport->mp_SigBit);
  73. X      else
  74. X         break;
  75. X   }
  76. X}
  77. X
  78. Xvoid dmpport(flags, x, y)
  79. Xlong flags;
  80. Xint x, y;
  81. X{
  82. X   register struct IODRPReq *ioreq;
  83. X
  84. X   ioreq = &printerIO->iodrp;
  85. X   ioreq->io_Command = PRD_DUMPRPORT;
  86. X   ioreq->io_RastPort = &rastport;
  87. X   ioreq->io_ColorMap = &dummyColorMap;
  88. X   ioreq->io_Modes = 0;
  89. X   ioreq->io_SrcX = 0;
  90. X   ioreq->io_SrcY = 0;
  91. X   ioreq->io_SrcWidth = x;
  92. X   ioreq->io_SrcHeight = y;
  93. X   ioreq->io_DestCols = x;
  94. X   ioreq->io_DestRows = y;
  95. X   ioreq->io_Special = flags | SPECIAL_TRUSTME ;
  96. X   doio();
  97. X}
  98. X
  99. Xstatic long bitmapx, bitmapy, wordsperrow;
  100. Xstatic short *bitmap;
  101. X
  102. Xint mapinit(bmapx, bmapy)
  103. Xlong bmapx, bmapy;
  104. X{
  105. X   bitmapx = bmapx;
  106. X   bitmapy = bmapy;
  107. X   wordsperrow = (bmapx+15)/16;
  108. X   Bitmap.BytesPerRow = wordsperrow * 2;
  109. X   Bitmap.Rows = bmapy;
  110. X   /* Allocate memory for bitmap */
  111. X   if((bitmap = (short *)calloc(wordsperrow * 2, (int)bmapy)) == NULL) {
  112. X      fprintf(stderr,"\nCan't allocate memory for bitmap dump.\n");
  113. X      return(1);
  114. X   }
  115. X   Bitmap.Planes[0] = (PLANEPTR)bitmap;
  116. X   return(0);
  117. X}
  118. X
  119. Xvoid mapfree()
  120. X{
  121. X   free((VOID *)bitmap);
  122. X}
  123. X
  124. Xvoid mapclear()
  125. X{
  126. X   memset((char *)bitmap,'\0',(int)(wordsperrow * (long)bitmapy * 2));
  127. X}
  128. X
  129. X/* Function to draw the line in the bitmap */
  130. Xvoid mapline(x1,y1,x2,y2)
  131. Xregister int x1,y1,x2,y2;
  132. X{
  133. X   register short *p ;
  134. X   register unsigned int b ;
  135. X   register int t ;
  136. X   int d ;
  137. X   int nextrow ;
  138. X
  139. X   /* we always want to go left to right. */
  140. X   if (x1 > x2) {
  141. X      t = x1 ; x1 = x2 ; x2 = t ;
  142. X      t = y1 ; y1 = y2 ; y2 = t ;
  143. X   }
  144. X   p = bitmap + y1 * wordsperrow ;
  145. X   /* we always want to go `up'. */
  146. X   if (y2 > y1)
  147. X      nextrow = wordsperrow ;
  148. X   else {
  149. X      y2 = y1 * 2 - y2 ;
  150. X      nextrow = - wordsperrow ;
  151. X   }
  152. X   b = 1L << (15 - (x1 & 15)) ;
  153. X   p += (x1 >> 4) ;
  154. X   x2 -= x1 ;
  155. X   y2 -= y1 ;
  156. X   /* two routines, one for major in x, one for major in y */
  157. X   if (y2 > x2) {
  158. X      d = y2 ;
  159. X      t = x2 / 2 ;
  160. X      y1 = y2 ;
  161. X      while (y1 >= 0) {
  162. X         *p |= b ;
  163. X         p += nextrow ;
  164. X         t += x2 ;
  165. X         if (t >= d) {
  166. X            t -= d ;
  167. X            b >>= 1 ;
  168. X            if (b == 0) {
  169. X               b = 0x8000 ;
  170. X               p++ ;
  171. X            }
  172. X         }
  173. X         y1-- ;
  174. X      }
  175. X   } else {
  176. X      d = x2 ;
  177. X      t = y2 / 2 ;
  178. X      x1 = x2 ;
  179. X      while (x1 >= 0) {
  180. X         *p |= b ;
  181. X         b >>= 1 ;
  182. X         if (b == 0) {
  183. X            b = 0x8000 ;
  184. X            p++ ;
  185. X         }
  186. X         t += y2 ;
  187. X         if (t >= d) {
  188. X            t -= d ;
  189. X            p += nextrow ;
  190. X         }
  191. X         x1-- ;
  192. X      }
  193. X   }
  194. X}
  195. X
  196. Xint openprinter()
  197. X{
  198. X   replyport = (struct MsgPort *)CreatePort("PLPlot.PIO",0L);
  199. X   if(replyport == NULL){
  200. X      fprintf(stderr,"Couldn't open reply port for printer dump.\n");
  201. X      return(1);
  202. X   }
  203. X
  204. X   printerIO = (union printerIO *)
  205. X               AllocMem((long)sizeof(union printerIO),
  206. X                        (long)(MEMF_CLEAR | MEMF_PUBLIC));
  207. X   if(printerIO == NULL) {
  208. X      DeletePort(replyport);
  209. X      fprintf(stderr,"Couldn't create IO request block for printer dump.\n");
  210. X      return(1);
  211. X   }
  212. X   printerIO->ios.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  213. X   printerIO->ios.io_Message.mn_Length = sizeof(union printerIO);
  214. X   printerIO->ios.io_Message.mn_ReplyPort = replyport;
  215. X
  216. X   if(OpenDevice("printer.device",0L,(struct IORequest *)printerIO,0L)!=NULL) {
  217. X      FreeMem((VOID *)printerIO,(long)sizeof(union printerIO));
  218. X      DeletePort(replyport);
  219. X      fprintf(stderr,"Error opening printer device.\n");
  220. X      return(1);
  221. X   }
  222. X
  223. X   PD = (struct PrinterData *)printerIO->iodrp.io_Device;
  224. X   PED = &PD->pd_SegmentData->ps_PED;
  225. X   return(0);
  226. X}
  227. X
  228. Xvoid closeprinter()
  229. X{
  230. X   CloseDevice((struct IORequest *)printerIO);
  231. X   FreeMem((VOID *)printerIO,(long)sizeof(union printerIO));
  232. X   DeletePort(replyport);
  233. X}
  234. X
  235. Xint queryprint(bmapx, bmapy, bmapxmax, bmapymax, xdpi, ydpi)
  236. Xlong *bmapx, *bmapy, *bmapxmax, *bmapymax, *xdpi, *ydpi;
  237. X{
  238. X   int mode;
  239. X   Bitmap.BytesPerRow = 0;
  240. X   Bitmap.Rows = 0;
  241. X   Bitmap.Depth = 1;
  242. X   rastport.BitMap = &Bitmap;
  243. X   dmpport((long)(SPECIAL_NOPRINT), 0, 0);
  244. X
  245. X   *bmapxmax = PED->ped_MaxXDots;
  246. X   *bmapymax = 95*PED->ped_YDotsInch/10;  /* 9.5" to prevent problems */
  247. X
  248. X   *xdpi = PED->ped_XDotsInch;
  249. X   *ydpi = PED->ped_YDotsInch;
  250. X
  251. X   if(PD->pd_Preferences.PrintFlags & BOUNDED_DIMENSIONS) {
  252. X      *bmapx = PD->pd_Preferences.PrintMaxWidth*PED->ped_XDotsInch/10;
  253. X      *bmapy = PD->pd_Preferences.PrintMaxHeight*PED->ped_YDotsInch/10;
  254. X      mode = 1;
  255. X   }
  256. X   else if(PD->pd_Preferences.PrintFlags & ABSOLUTE_DIMENSIONS) {
  257. X      *bmapx = PD->pd_Preferences.PrintMaxWidth*PED->ped_XDotsInch/10;
  258. X      *bmapy = PD->pd_Preferences.PrintMaxHeight*PED->ped_YDotsInch/10;
  259. X      mode = 0;
  260. X   }
  261. X   else if(PD->pd_Preferences.PrintFlags & PIXEL_DIMENSIONS) {
  262. X      *bmapx = PD->pd_Preferences.PrintMaxWidth;
  263. X      *bmapy = PD->pd_Preferences.PrintMaxHeight;
  264. X      mode = 0;
  265. X   }
  266. X   else {
  267. X      *bmapx = *bmapxmax;
  268. X      *bmapy = *bmapymax;
  269. X      mode = 1;
  270. X   }
  271. X
  272. X   PD->pd_Preferences.PrintImage = IMAGE_NEGATIVE;
  273. X   PD->pd_Preferences.PrintShade = SHADE_BW;
  274. X   PD->pd_Preferences.PrintThreshold = 7;
  275. X   PD->pd_Preferences.PrintAspect = ASPECT_HORIZ;
  276. X   PD->pd_Preferences.PrintFlags = INTEGER_SCALING;
  277. X   return(mode);
  278. X}
  279. X
  280. Xvoid ejectpage()
  281. X{
  282. X   printerIO->ios.io_Command = PRD_RAWWRITE;
  283. X   printerIO->ios.io_Data = (APTR)"\014" ;
  284. X   printerIO->ios.io_Length = 1 ;
  285. X   doio() ;
  286. X}
  287. X
  288. X/* If type = 0 dump the plplot window to the printer with full preferences
  289. X   support, i.e. color, shading, threshold, etc.  Otherwise we override many
  290. X   of the preferences selections, create a full page black and white
  291. X   bitmap and dump it to the printer. */
  292. Xvoid screendump(type)
  293. XPLINT type;
  294. X{
  295. X   register struct IODRPReq *ioreq;
  296. X   long bmapx, bmapy;
  297. X   long cxy, x1, y1;
  298. X   long dwidth, dheight, xlas, ylas, xnew, ynew;
  299. X   int penwid=1;
  300. X
  301. X   if(type != 0 && fbuffer == 0)
  302. X      return;
  303. X   if(openprinter())  /* return if error */
  304. X      return;
  305. X
  306. X   ioreq = &printerIO->iodrp;
  307. X
  308. X   if(type == 0) {
  309. X      ioreq->io_Command = PRD_DUMPRPORT;
  310. X      ioreq->io_RastPort = PLWRPort;
  311. X      ioreq->io_ColorMap = PLScreen->ViewPort.ColorMap;
  312. X      ioreq->io_Modes = PLScreen->ViewPort.Modes;
  313. X      ioreq->io_SrcX = XOffset;
  314. X      ioreq->io_SrcY = YOffset;
  315. X      ioreq->io_SrcWidth = PLWidth;
  316. X      ioreq->io_SrcHeight = PLHeight;
  317. X      ioreq->io_DestCols = 0;
  318. X      ioreq->io_DestRows = 0;
  319. X      ioreq->io_Special = SPECIAL_FULLROWS | SPECIAL_FULLCOLS |
  320. X                          SPECIAL_TRUSTME ;
  321. X      doio();
  322. X   }
  323. X   else {
  324. X      /* get bmapx and bmapy (the others are dummy variables) */
  325. X      queryprint(&bmapx,&bmapy,&dwidth,&dheight,&dwidth, &dheight);
  326. X
  327. X      /* Set up map */
  328. X      if(mapinit(bmapx,bmapy)) {
  329. X         closeprinter();
  330. X         return;
  331. X      }
  332. X
  333. X      prepupdate();
  334. X
  335. X      dwidth = bmapx - 2;
  336. X      dheight = bmapy - 2;
  337. X      while(!getpoint(&cxy, &x1, &y1)) {
  338. X         if(cxy == PENU) {
  339. X            if(type == 1) {
  340. X               xlas = ((long)dheight*(long)x1)/InitPLWidth;
  341. X               ylas = ((long)dwidth*(long)y1)/InitPLHeight;
  342. X            }
  343. X            else {
  344. X               xlas = ((long)dwidth*(long)x1)/InitPLWidth;
  345. X               ylas = ((long)dheight*(long)y1)/InitPLHeight;
  346. X            }
  347. X         }
  348. X         else if(cxy == PEND) {
  349. X            if(type == 1) {
  350. X               xnew = ((long)dheight*(long)x1)/InitPLWidth;
  351. X               ynew = ((long)dwidth*(long)y1)/InitPLHeight;
  352. X               switch (penwid) {
  353. X                  case 3:
  354. X                     mapline(ylas,xlas,ynew,xnew);
  355. X                  case 2:
  356. X                     mapline(ylas+2,xlas+2,ynew+2,xnew+2);
  357. X                  case 1:
  358. X                  default:
  359. X                     mapline(ylas+1,xlas+1,ynew+1,xnew+1);
  360. X               }
  361. X            }
  362. X            else {
  363. X               xnew = ((long)dwidth*(long)x1)/InitPLWidth;
  364. X               ynew = ((long)dheight*(long)y1)/InitPLHeight;
  365. X               switch (penwid) {
  366. X                  case 3:
  367. X                     mapline(xlas,dheight-ylas,xnew,dheight-ynew);
  368. X                  case 2:
  369. X                     mapline(xlas+2,dheight-ylas+2,xnew+1,dheight-ynew+2);
  370. X                  case 1:
  371. X                  default:
  372. X                     mapline(xlas+1,dheight-ylas+1,xnew+1,dheight-ynew+1);
  373. X               }
  374. X            }
  375. X            xlas = xnew;
  376. X            ylas = ynew;
  377. X         }
  378. X         else if(cxy == SPEN) {
  379. X            ;
  380. X         }
  381. X         else if(cxy == PWID) {
  382. X            penwid = x1;
  383. X         }
  384. X      }
  385. X      finiupdate();
  386. X
  387. X      dmpport(0L, bmapx, bmapy);
  388. X      mapfree();
  389. X   }
  390. X   closeprinter();
  391. X}
  392. X
  393. X/* prepupdate() flushes and rewinds the plot buffer file.  This should always
  394. X   be called before attempting to read the buffer file. */
  395. Xvoid prepupdate()
  396. X{
  397. X   if(fbuffer) {
  398. X      fflush(PlotFile);
  399. X      rewind(PlotFile);
  400. X   }
  401. X}
  402. X
  403. X/* Use getpoint to read the next command in the plot buffer file. */
  404. X/* Returns 0 if okay or 1 if end of file. */
  405. Xint getpoint(com, x, y)
  406. Xlong *com, *x, *y;
  407. X{
  408. X   short csh, xsh, ysh;
  409. X
  410. X   if(!fread((char *)&csh,sizeof(short),1,PlotFile))
  411. X      return(1);
  412. X
  413. X   *com = csh;
  414. X   if(csh == PENU || csh == PEND) {
  415. X      fread((char *)&xsh,sizeof(short),1,PlotFile);
  416. X      fread((char *)&ysh,sizeof(short),1,PlotFile);
  417. X      *x = xsh;
  418. X      *y = ysh;
  419. X   }
  420. X   else if(csh == SPEN || csh == PWID) {
  421. X      fread((char *)&xsh,sizeof(short),1,PlotFile);
  422. X      *x = xsh;
  423. X   }
  424. X
  425. X   return(0);
  426. X}
  427. X
  428. Xvoid finiupdate()
  429. X{
  430. X   fseek(PlotFile,0L,2);
  431. X}
  432. X
  433. Xstatic long iffpos ;
  434. Xstatic short curbyte ;
  435. Xstatic short curcount ;
  436. Xstatic short runcount ;
  437. Xstatic FILE *OutFile;
  438. X
  439. Xstruct BitMapHeader {
  440. X   UWORD w, h;
  441. X   WORD  x, y;
  442. X   UBYTE nPlanes;
  443. X   UBYTE masking;
  444. X   UBYTE compression;
  445. X   UBYTE pad1;
  446. X   UWORD transparentColor;
  447. X   UBYTE xAspect, yAspect;
  448. X   WORD pageWidth, pageHeight;
  449. X} bmhd;
  450. X
  451. Xstatic void iffobyte(b)
  452. Xregister int b ;
  453. X{
  454. X   putc(b, OutFile) ;
  455. X   iffpos++ ;
  456. X}
  457. Xchar outchunk[256] ;
  458. X
  459. Xstatic void iffoutbyte(b)
  460. Xregister int b ;
  461. X{
  462. X   register int i ;
  463. X
  464. X   if (b == curbyte && runcount < 125) {
  465. X      runcount++ ;
  466. X   } else {
  467. X      if (runcount > 2) {
  468. X         if (curcount > 0) {
  469. X            iffobyte(curcount-1) ;
  470. X            for (i=0; i<curcount; i++)
  471. X               iffobyte(outchunk[i]) ;
  472. X            curcount = 0 ;
  473. X         }
  474. X         iffobyte(256 - runcount + 1) ;
  475. X         iffobyte(curbyte) ;
  476. X      } else {
  477. X         while (runcount > 0) {
  478. X            outchunk[curcount++] = curbyte ;
  479. X            runcount-- ;
  480. X         }
  481. X         if (curcount > 110) {
  482. X            iffobyte(curcount-1) ;
  483. X            for (i=0; i<curcount; i++)
  484. X               iffobyte(outchunk[i]) ;
  485. X            curcount = 0 ;
  486. X         }
  487. X      }
  488. X      curbyte = b ;
  489. X      runcount = 1 ;
  490. X   }
  491. X}
  492. X
  493. Xstatic void finishrow()
  494. X{
  495. X   register int i ;
  496. X
  497. X   if (runcount <= 2) {
  498. X      while (runcount > 0) {
  499. X         outchunk[curcount++] = curbyte ;
  500. X         runcount-- ;
  501. X      }
  502. X   }
  503. X   if (curcount > 0) {
  504. X      iffobyte(curcount-1) ;
  505. X      for (i=0; i<curcount; i++)
  506. X         iffobyte(outchunk[i]) ;
  507. X      curcount = 0 ;
  508. X   }
  509. X   if (runcount > 0) {
  510. X      iffobyte(256 - runcount + 1) ;
  511. X      iffobyte(curbyte) ;
  512. X      curbyte = -1 ;
  513. X      runcount = 0 ;
  514. X   }
  515. X}
  516. X
  517. X#define BADFLAGS    (SPRITES|VP_HIDE|GENLOCK_AUDIO|GENLOCK_VIDEO)
  518. X#define FLAGMASK    (~BADFLAGS)
  519. X#define CAMGMASK    (FLAGMASK & 0x0000FFFFL)
  520. X
  521. X/* Routine to write out color bitmap. */
  522. Xvoid saveiff()
  523. X{
  524. X   long int formlen=0, formpos, bmhdlen, camglen, camgbod;
  525. X   long int bodylen=0, bodypos, cmaplen;
  526. X   long int numcolors, rowlen, rowoff, coloff;
  527. X   short int i, j, k;
  528. X   UWORD *coltable;
  529. X   UBYTE *byteptr, rgb[3];
  530. X   struct BitMap *PLBitMap;
  531. X   char *filename;
  532. X   FILE *IFFFile;
  533. X   char *plfilereq();
  534. X
  535. X   filename = plfilereq();
  536. X   if(!filename)
  537. X      return;
  538. X
  539. X   if((IFFFile = fopen(filename,"w+"))==NULL) {
  540. X      fprintf(stderr,"Can't open %s\n",filename);
  541. X      return;
  542. X   }
  543. X
  544. X   iffpos = 0;
  545. X   curbyte = -1;
  546. X   curcount = 0;
  547. X   runcount = 0;
  548. X   OutFile = IFFFile;
  549. X
  550. X   bmhdlen = sizeof(struct BitMapHeader);
  551. X   camglen = 4;
  552. X   PLBitMap = &PLScreen->BitMap;
  553. X
  554. X   fwrite("FORM",sizeof(char),4,IFFFile);
  555. X   formpos = ftell(IFFFile);
  556. X   fwrite((char *)&formlen,sizeof(long),1,IFFFile);
  557. X
  558. X   fwrite("ILBM",sizeof(char),4,IFFFile);
  559. X   formlen += 4;
  560. X
  561. X   fwrite("BMHD",sizeof(char),4,IFFFile);
  562. X   formlen += 4;
  563. X   fwrite((char *)&bmhdlen,sizeof(long),1,IFFFile);
  564. X   formlen += 4;
  565. X   bmhd.w = 16*((PLWidth+15)/16);
  566. X   bmhd.h = PLHeight;
  567. X   bmhd.x = PLWindow->LeftEdge + XOffset;
  568. X   bmhd.y = PLWindow->TopEdge + YOffset;
  569. X   bmhd.nPlanes = PLBitMap->Depth;
  570. X   bmhd.masking = 0;
  571. X   bmhd.compression = 1;
  572. X   bmhd.pad1 = 0;
  573. X   bmhd.transparentColor = 0;
  574. X   bmhd.xAspect = 10;
  575. X   bmhd.yAspect = 11;
  576. X   bmhd.pageWidth = PLScreen->Width;
  577. X   bmhd.pageHeight = PLScreen->Height;
  578. X   fwrite((char *)&bmhd,bmhdlen,1,IFFFile);
  579. X   formlen += bmhdlen;
  580. X
  581. X   fwrite("CAMG",sizeof(char),4,IFFFile);
  582. X   formlen += 4;
  583. X   fwrite((char *)&camglen,sizeof(long),1,IFFFile);
  584. X   formlen += 4;
  585. X   camgbod = PLScreen->ViewPort.Modes & CAMGMASK;
  586. X   fwrite((char *)&camgbod,sizeof(long),1,IFFFile);
  587. X   formlen += 4;
  588. X
  589. X   fwrite("CMAP",sizeof(char),4,IFFFile);
  590. X   formlen += 4;
  591. X   numcolors = 1;
  592. X   for(i=PLBitMap->Depth; i>0; i--)
  593. X      numcolors *= 2;
  594. X   cmaplen = numcolors*3;
  595. X   fwrite((char *)&cmaplen,sizeof(long),1,IFFFile);
  596. X   formlen += 4;
  597. X   coltable = (UWORD *)PLCMap->ColorTable;
  598. X   for(i=0; i<numcolors; i++) {
  599. X      rgb[0] = (*coltable >> 4) & 0xf0;
  600. X      rgb[1] = *coltable & 0xf0;
  601. X      rgb[2] = (*coltable << 4) & 0xf0;
  602. X      fwrite((char *)rgb,sizeof(UBYTE),3,IFFFile);
  603. X      formlen += 3;
  604. X      coltable++;
  605. X   }
  606. X
  607. X   fwrite("BODY",sizeof(char),4,IFFFile);
  608. X   formlen += 4;
  609. X   bodypos = ftell(IFFFile);
  610. X   fwrite((char *)&bodylen,sizeof(long),1,IFFFile);
  611. X   formlen += 4;
  612. X   rowlen = ((PLWidth+15)/16);
  613. X   rowlen *= 2;
  614. X   rowoff = (PLWindow->TopEdge + YOffset)*PLBitMap->BytesPerRow;
  615. X   coloff = (PLWindow->LeftEdge+ XOffset)/8;
  616. X   for(i=0; i<PLHeight; i++) {
  617. X      for(j=0; j<PLBitMap->Depth; j++) {
  618. X         byteptr = (UBYTE *)PLBitMap->Planes[j] + rowoff + coloff;
  619. X         for(k=0; k<rowlen; k++)
  620. X            iffoutbyte(*byteptr++ & 255);
  621. X         finishrow();
  622. X      }
  623. X      rowoff += PLBitMap->BytesPerRow;
  624. X   }
  625. X   if(iffpos & 1)
  626. X      iffobyte(0);
  627. X   bodylen = iffpos;
  628. X   formlen += iffpos;
  629. X   fflush(IFFFile);
  630. X   fseek(IFFFile,formpos,0);
  631. X   fwrite((char *)&formlen,sizeof(long),1,IFFFile);
  632. X   fseek(IFFFile,bodypos,0);
  633. X   fwrite((char *)&bodylen,sizeof(long),1,IFFFile);
  634. X   fclose(IFFFile);
  635. X}
  636. X
  637. X/*
  638. X *   Code we steal to write a black and white IFF file.
  639. X */
  640. Xstatic struct iffhead {
  641. X   char formname[4] ;
  642. X   long formlen ; /* fill me in */
  643. X   char ilbmname[4] ;
  644. X   char bmhdname[4] ;
  645. X   long bmhdlen ;
  646. X   short w, h ; /* fill me in */
  647. X   long dummy0 ;
  648. X   char numplanes, masking, compression, pad1 ;
  649. X   short tc ;
  650. X   char xas, yas ;
  651. X   short pw, ph ;
  652. X   char cmapname[4] ;
  653. X   long cmaplen ;
  654. X   char r0, g0, b0, r1, g1, b1 ;
  655. X   char bodyname[4] ;
  656. X   long bodylen ; /* fill me in */
  657. X} iffhead = { {'F','O','R','M'}, 0, {'I','L','B','M'}, {'B','M','H','D'}, 20,
  658. X      0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 320, 200, {'C','M','A','P'}, 6, 240, 240,
  659. X      240, 0, 0, 0, {'B','O','D','Y'}, 0 } ;
  660. X
  661. X/*
  662. X *   Finally we get into the nitty gritty of writing the stupid file.
  663. X */
  664. Xvoid iffwritefile(xdpi, ydpi, File)
  665. XPLINT xdpi, ydpi;
  666. XFILE *File;
  667. X{
  668. X   register int i, j ;
  669. X   register short *p;
  670. X
  671. X   p = bitmap;
  672. X   OutFile = File;
  673. X   fwrite((char *)&iffhead, 1, sizeof(struct iffhead), OutFile) ;
  674. X   iffpos = 0 ;
  675. X   curbyte = -1;
  676. X   curcount = 0;
  677. X   runcount = 0;
  678. X   for (j=0; j<bitmapy; j++) {
  679. X      for (i=wordsperrow; i; i--, p++) {
  680. X         iffoutbyte((*p >> 8) & 255) ;
  681. X         iffoutbyte(*p & 255) ;
  682. X      }
  683. X      finishrow() ;
  684. X   }
  685. X   if (iffpos & 1)
  686. X      iffobyte(0) ;
  687. X   fseek(OutFile, 0L, 0) ;
  688. X   iffhead.w = bitmapx ;
  689. X   iffhead.h = bitmapy ;
  690. X   iffhead.pw = bitmapx ;
  691. X   iffhead.ph = bitmapy ;
  692. X   iffhead.formlen = iffpos + sizeof(struct iffhead) - 8 ;
  693. X   iffhead.bodylen = iffpos ;
  694. X   iffhead.xas = xdpi ;
  695. X   iffhead.yas = ydpi ;
  696. X   fwrite((char *)&iffhead, 1, sizeof(struct iffhead), OutFile) ;
  697. X}
  698. X
  699. X/* Use 1.3 palette program to set colors. */
  700. Xvoid plcolreq()
  701. X{
  702. X   short i;
  703. X   extern PLINT MaxColors;
  704. X   struct FileLock *lock;
  705. X   struct Process *thisproc;
  706. X   APTR winptr;
  707. X
  708. X   /* This ensures that a requester won't appear for tools: or sys:
  709. X      if they don't exist */
  710. X   thisproc = (struct Process *)FindTask(0);
  711. X   winptr = thisproc->pr_WindowPtr;
  712. X   thisproc->pr_WindowPtr = (APTR)-1;  /* No window */
  713. X
  714. X   /* Check to see if palette is in tools: or sys:tools */
  715. X   if(lock = (struct FileLock *)Lock("tools:palette",ACCESS_READ)) {
  716. X      Execute("tools:palette",0,0);
  717. X      UnLock((BPTR)lock);
  718. X   }
  719. X   else if(lock = (struct FileLock *)Lock("sys:tools/palette",ACCESS_READ)) {
  720. X      Execute("sys:tools/palette",0,0);
  721. X      UnLock((BPTR)lock);
  722. X   }
  723. X   /* Can't find palette so just return */
  724. X   else {
  725. X      thisproc->pr_WindowPtr = winptr;
  726. X      return;
  727. X   }
  728. X
  729. X   /* Restore window pointer */
  730. X   thisproc->pr_WindowPtr = winptr;
  731. X
  732. X   /* Save new colors in PLCurPrefs. */
  733. X   for(i=0; i<MaxColors; i++)
  734. X      PLCurPrefs.Color[i] = GetRGB4(PLCMap,i);
  735. X
  736. X}
  737. X
  738. X#define PLOKGAD    0
  739. X#define PLCAGAD    1
  740. X#define PLSTGAD    2
  741. X
  742. Xstatic UBYTE Gadget3SIBuff[80];
  743. Xstatic struct StringInfo Gadget3SInfo = {
  744. X        Gadget3SIBuff,  /* buffer where text will be edited */
  745. X        NULL,   /* optional undo buffer */
  746. X        0,      /* character position in buffer */
  747. X        80,     /* maximum number of characters to allow */
  748. X        0,      /* first displayed character buffer position */
  749. X        0,0,0,0,0,      /* Intuition initialized and maintained variables */
  750. X        0,      /* Rastport of gadget */
  751. X        0,      /* initial value for integer gadgets */
  752. X        NULL    /* alternate keymap (fill in if you set the flag) */
  753. X};
  754. X
  755. Xstatic struct Gadget Gadget3 = {
  756. X        NULL,   /* next gadget */
  757. X        11,30,  /* origin XY of hit box relative to window TopLeft */
  758. X        158,9,  /* hit box width and height */
  759. X        NULL,   /* gadget flags */
  760. X        RELVERIFY+ENDGADGET+STRINGCENTER,       /* activation flags */
  761. X        STRGADGET+REQGADGET,    /* gadget type flags */
  762. X        NULL,   /* gadget border or image to be rendered */
  763. X        NULL,   /* alternate imagery for selection */
  764. X        NULL,   /* first IntuiText structure */
  765. X        NULL,   /* gadget mutual-exclude long word */
  766. X        (APTR)&Gadget3SInfo,    /* SpecialInfo structure */
  767. X        PLSTGAD,        /* user-definable data */
  768. X        NULL    /* pointer to user-definable data */
  769. X};
  770. X
  771. Xstatic SHORT BorderVectors1[] = {
  772. X        0,0,
  773. X        61,0,
  774. X        61,16,
  775. X        0,16,
  776. X        0,0
  777. X};
  778. Xstatic struct Border Border1 = {
  779. X        -1,-1,  /* XY origin relative to container TopLeft */
  780. X        1,0,JAM1,       /* front pen, back pen and drawmode */
  781. X        5,      /* number of XY vectors */
  782. X        BorderVectors1, /* pointer to XY vectors */
  783. X        NULL    /* next border in list */
  784. X};
  785. X
  786. Xstatic struct IntuiText IText1 = {
  787. X        3,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  788. X        7,4,    /* XY origin relative to container TopLeft */
  789. X        NULL,   /* font pointer or NULL for default */
  790. X        "CANCEL",       /* pointer to text */
  791. X        NULL    /* next IntuiText structure */
  792. X};
  793. X
  794. Xstatic struct Gadget Gadget2 = {
  795. X        &Gadget3,       /* next gadget */
  796. X        110,65, /* origin XY of hit box relative to window TopLeft */
  797. X        60,15,  /* hit box width and height */
  798. X        NULL,   /* gadget flags */
  799. X        RELVERIFY+ENDGADGET,    /* activation flags */
  800. X        BOOLGADGET+REQGADGET,   /* gadget type flags */
  801. X        (APTR)&Border1, /* gadget border or image to be rendered */
  802. X        NULL,   /* alternate imagery for selection */
  803. X        &IText1,        /* first IntuiText structure */
  804. X        NULL,   /* gadget mutual-exclude long word */
  805. X        NULL,   /* SpecialInfo structure */
  806. X        PLCAGAD,        /* user-definable data */
  807. X        NULL    /* pointer to user-definable data */
  808. X};
  809. X
  810. Xstatic SHORT BorderVectors2[] = {
  811. X        0,0,
  812. X        61,0,
  813. X        61,16,
  814. X        0,16,
  815. X        0,0
  816. X};
  817. Xstatic struct Border Border2 = {
  818. X        -1,-1,  /* XY origin relative to container TopLeft */
  819. X        1,0,JAM1,       /* front pen, back pen and drawmode */
  820. X        5,      /* number of XY vectors */
  821. X        BorderVectors2, /* pointer to XY vectors */
  822. X        NULL    /* next border in list */
  823. X};
  824. X
  825. Xstatic struct IntuiText IText2 = {
  826. X        3,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  827. X        24,4,   /* XY origin relative to container TopLeft */
  828. X        NULL,   /* font pointer or NULL for default */
  829. X        "OK",   /* pointer to text */
  830. X        NULL    /* next IntuiText structure */
  831. X};
  832. X
  833. Xstatic struct Gadget Gadget1 = {
  834. X        &Gadget2,       /* next gadget */
  835. X        10,65,  /* origin XY of hit box relative to window TopLeft */
  836. X        60,15,  /* hit box width and height */
  837. X        NULL,   /* gadget flags */
  838. X        RELVERIFY+ENDGADGET,    /* activation flags */
  839. X        BOOLGADGET+REQGADGET,   /* gadget type flags */
  840. X        (APTR)&Border2, /* gadget border or image to be rendered */
  841. X        NULL,   /* alternate imagery for selection */
  842. X        &IText2,        /* first IntuiText structure */
  843. X        NULL,   /* gadget mutual-exclude long word */
  844. X        NULL,   /* SpecialInfo structure */
  845. X        PLOKGAD,        /* user-definable data */
  846. X        NULL    /* pointer to user-definable data */
  847. X};
  848. X
  849. X#define GadgetList1 Gadget1
  850. X
  851. Xstatic SHORT BorderVectors4[] = {
  852. X        0,0,
  853. X        161,0,
  854. X        161,12,
  855. X        0,12,
  856. X        0,0
  857. X};
  858. Xstatic struct Border Border4 = {
  859. X        9,28,   /* XY origin relative to container TopLeft */
  860. X        3,0,JAM1,       /* front pen, back pen and drawmode */
  861. X        5,      /* number of XY vectors */
  862. X        BorderVectors4, /* pointer to XY vectors */
  863. X        NULL    /* next border in list */
  864. X};
  865. X
  866. Xstatic SHORT BorderVectors3[] = {
  867. X        0,0,
  868. X        179,0,
  869. X        179,99,
  870. X        0,99,
  871. X        0,0
  872. X};
  873. Xstatic struct Border Border3 = {
  874. X        0,0,    /* XY origin relative to container TopLeft */
  875. X        3,0,JAM1,       /* front pen, back pen and drawmode */
  876. X        5,      /* number of XY vectors */
  877. X        BorderVectors3, /* pointer to XY vectors */
  878. X        &Border4        /* next border in list */
  879. X};
  880. X
  881. X#define BorderList1 Border3
  882. X
  883. Xstatic struct IntuiText IText3 = {
  884. X        3,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  885. X        41,17,  /* XY origin relative to container TopLeft */
  886. X        NULL,   /* font pointer or NULL for default */
  887. X        "IFF File Name",        /* pointer to text */
  888. X        NULL    /* next IntuiText structure */
  889. X};
  890. X
  891. X#define IntuiTextList1 IText3
  892. X
  893. Xstatic struct Requester PLFileReq = {
  894. X        NULL,   /* previous requester (filled in by Intuition) */
  895. X        5,15,   /* requester XY origin relative to TopLeft of window */
  896. X        180,100,        /* requester width and height */
  897. X        0,0,    /* relative to these mouse offsets if POINTREL is set */
  898. X        &GadgetList1,   /* gadget list */
  899. X        &BorderList1,   /* box's border */
  900. X        &IntuiTextList1,        /* requester text */
  901. X        NULL,   /* requester flags */
  902. X        0,      /* back-plane fill pen */
  903. X        NULL,   /* leave these alone */
  904. X        NULL,   /* custom bitmap if PREDRAWN is set */
  905. X        NULL    /* leave this alone */
  906. X};
  907. X
  908. X/* end of PowerWindows source generation */
  909. X
  910. Xchar *plfilereq()
  911. X{
  912. X   ULONG oldFlags;
  913. X   USHORT gadid;
  914. X   char *file;
  915. X   struct IntuiMessage *message;
  916. X
  917. X   oldFlags = PLWindow->IDCMPFlags;
  918. X   ModifyIDCMP(PLWindow,GADGETUP);
  919. X   Request(&PLFileReq,PLWindow);
  920. X   Wait(1<<PLWindow->UserPort->mp_SigBit);
  921. X   message = (struct IntuiMessage *)GetMsg(PLWindow->UserPort);
  922. X   gadid = ((struct Gadget *)message->IAddress)->GadgetID;
  923. X   ReplyMsg((struct Message *)message);
  924. X   switch(gadid) {
  925. X      case PLOKGAD:
  926. X         if(Gadget3SIBuff[0] == NULL)
  927. X            file = NULL;
  928. X         else
  929. X            file = (char *)Gadget3SIBuff;
  930. X         break;
  931. X      case PLCAGAD:
  932. X         file = NULL;
  933. X         break;
  934. X      case PLSTGAD:
  935. X         if(Gadget3SIBuff[0] == NULL)
  936. X            file = NULL;
  937. X         else
  938. X            file = (char *)Gadget3SIBuff;
  939. X         break;
  940. X      default:
  941. X         break;
  942. X   }
  943. X   ModifyIDCMP(PLWindow,oldFlags);
  944. X   return(file);
  945. X}
  946. X
  947. X/* This routine disables all the gadgets attached to PLWindow.
  948. X   It's useful when saving the window as an IFF file or when dumping it
  949. X   to the printer. (We don't want the user moving the window around or
  950. X   resizing it during those periods.). We always disable the window sizing
  951. X   and close gadgets. If flag is zero we disable the dragging gadget also. */
  952. Xvoid disablegads(flag)
  953. XPLINT flag;
  954. X{
  955. X   int type;
  956. X   struct Gadget *gadget;
  957. X
  958. X   gadget = PLWindow->FirstGadget;
  959. X   while(gadget) {
  960. X     type = gadget->GadgetType & 0x00ff;
  961. X     if(type == SIZING || type == CLOSE || (type == WDRAGGING && !flag))
  962. X        OffGadget(gadget,PLWindow,0);
  963. X     gadget = gadget->NextGadget;
  964. X   }
  965. X}
  966. X
  967. Xvoid enablegads()
  968. X{
  969. X   struct Gadget *gadget;
  970. X
  971. X   gadget = PLWindow->FirstGadget;
  972. X   while(gadget) {
  973. X     OnGadget(gadget,PLWindow,0);
  974. X     gadget = gadget->NextGadget;
  975. X   }
  976. X   RefreshWindowFrame(PLWindow);
  977. X}
  978. X
  979. END_OF_FILE
  980. if test 26014 -ne `wc -c <'Amiga/plsupport.c'`; then
  981.     echo shar: \"'Amiga/plsupport.c'\" unpacked with wrong size!
  982. fi
  983. # end of 'Amiga/plsupport.c'
  984. fi
  985. echo shar: End of archive 9 \(of 12\).
  986. cp /dev/null ark9isdone
  987. MISSING=""
  988. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  989.     if test ! -f ark${I}isdone ; then
  990.     MISSING="${MISSING} ${I}"
  991.     fi
  992. done
  993. if test "${MISSING}" = "" ; then
  994.     echo You have unpacked all 12 archives.
  995.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  996. else
  997.     echo You still need to unpack the following archives:
  998.     echo "        " ${MISSING}
  999. fi
  1000. ##  End of shell archive.
  1001. exit 0
  1002. -- 
  1003. Submissions to comp.sources.amiga and comp.binaries.amiga should be sent to:
  1004.     amiga@cs.odu.edu    
  1005. or    amiga@xanth.cs.odu.edu    ( obsolescent mailers may need this address )
  1006. or    ...!uunet!xanth!amiga    ( very obsolescent mailers need this address )
  1007.  
  1008. Comments, questions, and suggestions s should be addressed to ``amiga-request''
  1009. (only use ``amiga'' for submissions) at the above addresses.
  1010.